$(function (){
    var layer = layui.layer
    $("#loginForm").submit(function (){
        let agreeValue = $("#agree").prop("checked")
        // console.log(agreeValue)
        if(!agreeValue){
            // alert("您未同意协议不能登录")
            layer.alert('您未同意协议不能登录')
            return false;
        }
        // 登录功能
        let username = $("#username").val()
        let password = $("#password").val();
        password = md5(password)
        $("#password").val(password)
        let jsonLogin = JSON.stringify({username,password})
        // console.log(jsonLogin)
        // return false;
        $.ajax({
            url:'/api/user/login',
            type:'post',
            dataType:'json',
            data:jsonLogin,
            contentType:'application/json;charset=utf-8',
            success: data=>{
                // console.log(data)
                if(data['code']===1008){
                    // 登录成功  页面跳转
                    layer.alert(data['msg'],function (){
                        layer.close()
                        window.location.href = '/index.html'
                    })

                }else{
                    layer.alert(data['msg'],function (){
                        layer.close()
                        // window.location.href = '/login.html'
                    })

                }
            }
        })
        return false
    })
})